package com.example.demo.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.entity.RegistrationEntity;
import com.example.demo.service.RegistrationService;
import com.example.demo.tool.ResponseResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@Api(tags = "入院登记")
public class RegistrationController {
    @Autowired
    private RegistrationService registrationService;

    @PostMapping("add/registrantion")
    public ResponseResult addlist(RegistrationEntity registrationEntity){
        registrationEntity.setCreateTime(new Date());
        registrationService.save(registrationEntity);
        return ResponseResult.success();
    }

    @GetMapping("allRegisterantion")
    public ResponseResult listAll(@ApiParam("页码，默认为1") @RequestParam(name = "pageNum",defaultValue = "1") Integer pageNum,
                                  @ApiParam("每页数量，默认为10") @RequestParam(name = "pageSize",defaultValue = "10") Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<RegistrationEntity> list = registrationService.list(new QueryWrapper<RegistrationEntity>().orderByDesc("create_time"));
        PageInfo<RegistrationEntity> page = new PageInfo<>(list);
        return ResponseResult.success(page);
    }
}
